package org.jeecg.modules.haili.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.haili.service.OriginOrderService;
import org.jeecg.modules.haili.entity.insurance.OriginInsOrder;
import org.jeecg.modules.haili.mapper.OriginInsOrderMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@DS("multi-sqlserver")
@Service
public class InsOrignOrderServiceImpl extends ServiceImpl<OriginInsOrderMapper, OriginInsOrder> implements OriginOrderService {

    private Logger logger = LoggerFactory.getLogger(InsOrignOrderServiceImpl.class);

    /**
     * 查找没有投保的保单
     *
     * @return
     */
    @Override
    public List<OriginInsOrder> findUnInsurancedOrder() {
        QueryWrapper<OriginInsOrder> countWrapper = new QueryWrapper<OriginInsOrder>();

        int countNum = this.baseMapper.countUnIns(countWrapper);
        logger.info("未投保的保单数量:" + countNum);
        QueryWrapper<OriginInsOrder> queryWrapper = new QueryWrapper<OriginInsOrder>();
        queryWrapper.isNull("danhao");
        queryWrapper.isNull("proposalno");
        queryWrapper.ge("ydate", "2021-08-21 00:00:00");
//        queryWrapper.orderByDesc("ydate");
        Page<OriginInsOrder> originInsOrderPage = new Page<>(1, 50);
        Page<OriginInsOrder> insOrderPage = this.baseMapper.selectCusPage(originInsOrderPage, queryWrapper);
        List<OriginInsOrder> originInsOrders = insOrderPage.getRecords();
        for (OriginInsOrder order : originInsOrders) {
            String uuid = UUID.randomUUID().toString().replaceAll("-", "");
            order.setUuid(uuid);
            this.baseMapper.updateById(order);
        }
        return originInsOrders;
    }
}
